#ifndef __BSP_CAN_H__
#define __BSP_CAN_H__

#include "stm32f10x.h"
#include "stm32f10x_can.h"

#define CAN_DEBUG                       1

#define FILTER_SIZE                     8
#define TX_BUFFER_SIZE                  64
#define RX_BUFFER_SIZE                  64

#define CAN_500K                        4
#define CAN_250K                        8
#define CAN_125K                        16
#define CAN_33K                         60
#define RCC_APBxPeriph_CAN_IO           RCC_APB2Periph_GPIOA
#define CAN_RXD                         GPIO_Pin_11
#define CAN_TXD                         GPIO_Pin_12
#define CAN_IO                          GPIOA
#define CAN_PinRemap                    DISABLE
#define flexcan_rx_callack			    USB_LP_CAN1_RX0_IRQHandler

typedef struct {
    //CanTxMsg *p_tx_msg;       //transmit buffer
    CanRxMsg *p_rx_msg;       //receive buffer
    //uint16_t tx_size;         //transmit size
    uint16_t rx_size;         //receive size

    __IO uint16_t w_offset;  //write offset
    __IO uint16_t r_offset;  //read offset
    __IO uint16_t rx_count;

    uint16_t filter_id[FILTER_SIZE];
} FlexcanData;

void bsp_can_init(uint8_t velocity);
void bsp_can_send(CanTxMsg *txMsg);
uint8_t bsp_can_recv(CanRxMsg *rxMsg);
void bsp_can_clear(void);
void bsp_can_filter(uint32_t id1, uint32_t id2, uint32_t mid1, uint32_t mid2);

void bsp_can_enable(uint8_t enable);
void bsp_can_nvic_init(void);
void bsp_can_gpio_init(void);

#endif
